package org.zjz.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.zjz.dao.MenuDao;
import org.zjz.pojo.Menu;
import org.zjz.service.MenuService;

@Service("menuService")
public class MenuServiceImpl implements MenuService{

	@Autowired
	private MenuDao menuDao;
	public Map<Menu,List<Menu>> selectMenu(Integer uid){
		Map<Menu,List<Menu>> map = new TreeMap<Menu,List<Menu>>();
		List<Menu> list;
		List<Menu> selList = menuDao.selectMenu(uid);
		for (Menu menu : selList) {
			System.out.println(menu.gethMid()+"\t"+menu.gethMname()+"\t"+menu.gethMpid());
		}
		for (Menu m : selList) {
			list = new ArrayList<Menu>();
			if(m.gethMpid()==null) {
				map.put(m, null);
			}
			for (Menu m2 : selList) {
				if(m2.gethMpid()==m.gethMid()) {
					list.add(m2);
				}
			}
			if(m.gethMpid()==null) {
				map.put(m, list);
			}
		}
		return map;
	}
}
